<template>
  <!-- 待分诊 -->
  <section>
    <el-form :inline="true" @submit.native.prevent="getData(-1)" style="text-align:right;">
      <el-form-item>
        <deptSearch v-model="form.deptId"></deptSearch>
      </el-form-item>
      <el-form-item>
        <!-- <el-input v-model="form.medicalCard" placeholder="请输入档案号"></el-input> -->
       <patientSearch v-model="form.patientId"></patientSearch>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit" circle icon="el-icon-search"></el-button>
      </el-form-item>
    </el-form>  
    <el-row :gutter="20">
      <el-col v-for="(item,index) in tableList" :key="index" :xs="12" :sm="12" :md="12" :lg="8" :xl="6" class="reserve-user-list">
        <div :class="['card-box','bg-sy']">
          <div class="card-nr">
            <div>
              <img v-if="!item.patientInfo.head" src="@/img/unknown-avatar.png" class="head-img" alt="" style="width:70px;height:70px;">
              <img v-else :src="item.patientInfo.head|imageUrl" class="head-img" style="width:70px;height:70px;">
            </div>
            <div style="overflow: hidden;">
              <p class="overflow-omit">
                <span style="font-size:18px;">{{item.patientInfo.name}}</span>
                &nbsp;
                 <span>（{{item.patientInfo.sex|toSex}}&nbsp;<span v-if="item.patientInfo.age>17">{{item.patientInfo.age}}岁</span><span v-else>{{item.patientInfo.birthday|toTimeContrast}}</span>）</span>
              </p>
              <div class="overflow-omit">登记科室：{{item.deptName}}（{{item.registerName}}）</div>
              <div class="overflow-omit">
                <!-- <span>预约医生：{{item.doctorName?item.doctorName:'无'}}</span>
                &nbsp; -->
                <span>等候时间：{{item.gmtCreate|computeHour}}</span>
              </div>
              <!-- <div class="overflow-omit">
                <span>预约时间：</span>
                <span v-if="item.dateDay">
                </span>
                <span v-else>无</span>
              </div> -->
              <div class="overflow-omit">预约内容：{{item.registerContent?item.registerContent:'无'}}</div>
            </div>
          </div>
          <div class="card-footer">
            <div @click="onWriteData(item,index)">完善信息</div>
            <div @click="onSelectDoctor(item,index)">选择医生</div>
          </div>
          <div class="zt-box">
            登记&nbsp;{{item.gmtCreate|hourDate}}
          </div>
          <div v-if="item.patientInfo.levelId" class="vip-box">
            <el-tooltip :content="item.patientInfo.levelName" placement="top">
              <img src="@/img/icon-vip.png" alt="">
            </el-tooltip>
          </div>
        </div>
      </el-col>
    </el-row>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br>
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <dialogSelectDoctor v-model="dialogSelectDoctor" :curItem="curItem" @success="successSelectDoctor"></dialogSelectDoctor>
    <dialogWriteData v-model="dialogWriteData" :patientId="curItem.patientInfo.patientId"></dialogWriteData>
  </section>
</template>
<script>
export default {
  props: ["qxBtns"],
  components: {
    dialogSelectDoctor: () => import("./dialogSelectDoctor.vue"),
    dialogWriteData: () => import("@/pages/_com/dialogWriteData.vue"),
    deptSearch: () => import("@/pages/_com/deptSearch.vue"),
    patientSearch: () => import("@/pages/_com/patientSearch.vue")
  },
  filters: {},
  data() {
    return {
      dialogWriteData: false,
      dialogSelectDoctor: false,
      curItem: {
        patientInfo: {
          patientId: ""
        }
      },
      curIndex: 0,
      form: {
        triageStatus: 1,
        deptId: "",
        medicalCard: "",
        patientId:"",
      },
      pager: { pageSize: 12, pageNum: 1, total: 0 },
      tableList: []
    };
  },
  created() {},
  mounted() {
    let th = this;
    th.getData();
  },
  methods: {
    //完善信息
    onWriteData(obj, index) {
      let th = this;
      th.dialogWriteData = true;
      th.curItem = obj;
      th.curIndex = index;
    },
    //选择医生完成
    successSelectDoctor() {
      let th = this;
      th.tableList.splice(th.curIndex, 1);
    },
    //选择医生
    onSelectDoctor(obj, index) {
      let th = this;
      if (!th.qxBtns.xzys) {
        th.$message.warning("权限不足");
        return;
      }
      th.dialogSelectDoctor = true;
      th.curItem = obj;
      th.curIndex = index;
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      th.showLoading();
      let j = {};
      Object.assign(j, th.form, th.pager);
      th.$api.getRegisterListInfo(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
        th.showLoading(false);
      });
    },
    //判断类名
    classToName(type) {
      switch (type) {
        case 1:
          return "bg-yjz";
          break;
        case 2:
          return "bg-sy";
          break;
        case 3:
          return "bg-hong";
          break;
        case 4:
          return "bg-yqx";
          break;
        case 5:
          return "bg-jzz";
          break;
        default:
          return "bg-dfz";
          break;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../_css/reserve.scss";
</style>